package com.group9.handinhand.controller.form;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import com.group9.handinhand.service.so.OfferSO;
/**
 * 
 * @class OfferCreateForm
 * Creates offer form.
 *
 */
public class OfferCreateForm {

	OfferSO offer = new OfferSO();
	String selectedTags;
	String endingDay;
	String endingHour;
	/**
	 * A getter method.
	 * @return offer
	 */
	public OfferSO getOffer() {
		return offer;
	}
	/**
	 * A setter method.
	 * @param offer
	 */
	public void setOffer(OfferSO offer) {
		this.offer = offer;
	}

	/**
	 * A getter method.
	 * @return EndingDay
	 */
	public String getEndingDay() {
		return endingDay;
	}
	/**
	 * A setter method.
	 * @param endingDay
	 */
	public void setEndingDay(String endingDay) {
		this.endingDay = endingDay;
	}
	/**
	 * A getter method.
	 * @return endingHour
	 */
	public String getEndingHour() {
		return endingHour;
	}
	/**
	 * A setter method.
	 * @param endingHour
	 */	
	public void setEndingHour(String endingHour) {
		this.endingHour = endingHour;
	}
	/**
	 * To string method which converts OfferCreateForm into a string.
	 */
	@Override
	public String toString() {
		return "OfferCreateForm [endingDay=" + endingDay + ", endingHour="
				+ endingHour + ", offer=" + offer + "]";
	}
	/**
	 * A set method.
	 * Sets the ending dates which include ending days and hours also.
	 */
	public void setEndDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		
		String endingDate = endingDay + " " + endingHour;
		
		try {
			offer.setExpirationDate(dateFormat.parse(endingDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
	}
	/**
	 * A getter method.
	 * @return selectedTags
	 */
	public String getSelectedTags() {
		return selectedTags;
	}
	/**
	 * A setter method.
	 * @param selectedTags
	 */
	public void setSelectedTags(String selectedTags) {
		this.selectedTags = selectedTags;
	}
	/**
	 * A getter method.
	 * @return the list of selected  tags as an array
	 */
	public List<String> getSelectedTagsAsList() {
		String[] tags = selectedTags.split(",");
		return Arrays.asList(tags);
	}

}
